{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b4e9296e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "# 导包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e522013f",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd1 = np.array([[1,2],[2,3],[3,4]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c09dec92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2],\n",
       "       [2, 3],\n",
       "       [3, 4]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "61d02e9e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "print(type(nd1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a64ba468",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [2 3]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "print(nd1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bf4347e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1.max()\n",
    "nd1.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d9d61b81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e968c401",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd2 = np.array([[\"1\",\"2\",\"3\"],[\"2\",\"3\",\"4\"]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b8170abe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['1', '2', '3'],\n",
       "       ['2', '3', '4']], dtype='<U1')"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "493b3bdc",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd2 = nd2.astype(\"int\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1ac84af5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "2ff558ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd3 = np.array([[1,2,3,],[4,5,6],[7,8,9],[1,2,3]])\n",
    "#四行三列矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "e35e25d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6],\n",
       "       [7, 8, 9],\n",
       "       [1, 2, 3]])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "fa1ad89d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 3)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3.shape\n",
    "#shape 查看矩阵结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "cd5950d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 切片索引\n",
    "nd3[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "48b0480d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 5, 6],\n",
       "       [7, 8, 9]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[1:3:1]\n",
    "#456,789"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "75ac883f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5, 6],\n",
       "       [8, 9]])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 切片\n",
    "# [行的切片,列的切片]\n",
    "# [行的起始位置:行的结束位置:步长,列的起始位置:列的结束位置:步长]\n",
    "nd3[1:3:1,1:3:1]\n",
    "#56,89"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "630dc293",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd4 = np.array([\n",
    "    [0,1,2,3,4,5],\n",
    "    [10,11,12,13,14,15],\n",
    "    [20,21,22,23,24,25],\n",
    "    [30,31,32,33,34,35],\n",
    "    [40,41,42,43,44,45],\n",
    "    [50,51,52,53,54,55],\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "daf758b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [10, 11, 12, 13, 14, 15],\n",
       "       [20, 21, 22, 23, 24, 25],\n",
       "       [30, 31, 32, 33, 34, 35],\n",
       "       [40, 41, 42, 43, 44, 45],\n",
       "       [50, 51, 52, 53, 54, 55]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "553a5d2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1, 12, 23, 34, 45])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4[(0,1,2,3,4),(1,2,3,4,5)]\n",
    "# 坐标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "3d874393",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2, 22, 52])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4[[0,2,5],2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "0e686a47",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd5 = np.array([1,0,1,0,0,1],dtype='bool')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "545e8ebd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2, 22, 52])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4[nd5,2]\n",
    "#布尔索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "01a8c6d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4%2==1\n",
    "#布尔索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "68e8c127",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  3,  5, 11, 13, 15, 21, 23, 25, 31, 33, 35, 41, 43, 45, 51, 53,\n",
       "       55])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4[nd4%2==1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "8428d02c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n"
     ]
    }
   ],
   "source": [
    "nd1 = np.array([[1,2,3],[4,5,6]])\n",
    "print(nd1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "bad727e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 3 4]\n",
      " [1 2 3]]\n"
     ]
    }
   ],
   "source": [
    "nd2 = np.array([[2,3,4],[1,2,3]])\n",
    "print(nd2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "064e0cc5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-1 -1 -1]\n",
      " [ 3  3  3]]\n",
      "[[-1 -1 -1]\n",
      " [ 3  3  3]]\n",
      "[[ 2  6 12]\n",
      " [ 4 10 18]]\n",
      "[[0.5        0.66666667 0.75      ]\n",
      " [4.         2.5        2.        ]]\n"
     ]
    }
   ],
   "source": [
    "#对位运算\n",
    "print(nd1-nd2)\n",
    "print(nd1-nd2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "61cf5406",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd3 = np.array([[1,2],[2,3],[3,4]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "247913e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[14, 20],\n",
       "       [32, 47]])"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(nd1,nd3)\n",
    "#矩阵乘法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "f0d6456e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3.        , 1.91666667],\n",
       "       [8.5       , 5.16666667]])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(nd1,1/nd3)\n",
    "#矩阵除法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f900426",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
